package com.djl.service.impl;

import com.djl.crowd.entity.Auth;
import com.djl.mapper.AuthMapper;
import com.djl.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author le
 * @Date 2021/12/23 14:30
 * @Version 1.0
 */
@Service
public class AuthServiceImpl implements AuthService {

    @Autowired
    private AuthMapper authMapper;



    @Override
    public List<String> getAssignedAuthNameByAdminId(Integer adminId) {
        authMapper.queryAssignedAuthNameByAdminId(adminId);
        return null;
    }

    @Override
    public void saveRoleAuthRelationShip(Map<String, List<Integer>> map) {
        List<Integer> roleIds = map.get("roleId");
        Integer roleId = roleIds.get(0);
        // 删除旧的关联关系
        authMapper.deleteOldRelationShip(roleId);
        // 获取authIdList
        List<Integer> authIdList = map.get("authIdArray");
        // 判断authIdList是否有效
        if (!authIdList.isEmpty()){
            authMapper.insertNewRelationShip(roleId,authIdList);
        }
    }

    @Override
    public List<Integer> queryAssignedAuthIdByRoleId(Integer roleId) {
        return authMapper.selectAssignedAuthIdByRoleId(roleId);
    }

    @Override
    public List<Auth> selectAll() {
        return authMapper.selectByExample(null);
    }
}
